package com.bobohost.crmrbac.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bobohost.crmrbac.pojo.po.QueryObject;
import com.bobohost.crmrbac.pojo.po.Role;
import com.bobohost.crmrbac.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 叶笑秋
 * @since 2025-05-21
 */
@Controller
@RequestMapping("/role")
@Slf4j
public class RoleController {
    @Autowired
    private RoleService roleService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")QueryObject queryObject) {
        IPage page = Page.of(queryObject.getCurrentPage(), queryObject.getPageSize());
        IPage<Role> pageResult= roleService.findRoleListPage( page);
        Map<String,Object> pageInfo=new HashMap<>();
        pageInfo.put("pageNum",pageResult.getCurrent());
        pageInfo.put("pages",pageResult.getPages());
        pageInfo.put("list",pageResult.getRecords());
        model.addAttribute("pageInfo",pageInfo);

        return "role/list";
    }

//    @RequestMapping("/list")
//    public String list(Model model,@ModelAttribute("qo") QueryObject queryObject){
//        //调用业务层获取数据
//        PageInfo<Role> pageInfo = roleService.selectDepartmentByCondition(queryObject);
//        //传到页面
//        model.addAttribute("pageInfo",pageInfo);
//        //跳转到页面
//        return "role/list";
//    }

}
